{% extends "scheduling/base.html" %}
{% load static %}
{% load tz %}

{% block content %}
<div class="container mt-4">
    <h2 class="mb-4">公交调度系统仪表盘</h2>

    <div class="row">
        <div class="col-md-3 mb-4">
            <div class="card bg-primary text-white">
                <div class="card-body text-center">
                    <h5><i class="fas fa-bus me-2"></i>车辆总数</h5>
                    <h1>{{ bus_count }}</h1>
                </div>
            </div>
        </div>

        <div class="col-md-3 mb-4">
            <div class="card bg-success text-white">
                <div class="card-body text-center">
                    <h5><i class="fas fa-user-tie me-2"></i>在岗司机</h5>
                    <h1>{{ driver_count }}</h1>
                </div>
            </div>
        </div>

        <div class="col-md-3 mb-4">
            <div class="card bg-info text-white">
                <div class="card-body text-center">
                    <h5><i class="fas fa-calendar-check me-2"></i>活跃班次</h5>
                    <h1>{{ active_schedules }}</h1>
                </div>
            </div>
        </div>

        <div class="col-md-3 mb-4">
            <div class="card bg-warning text-white">
                <div class="card-body text-center">
                    <h5><i class="fas fa-tools me-2"></i>维修车辆</h5>
                    <h1>{{ under_maintenance }}</h1>
                </div>
            </div>
        </div>
    </div>

    <div class="row mt-4">
        <div class="col-md-6 col-lg-4 mb-4">
            <div class="card h-100">
                <div class="card-header bg-warning text-white d-flex align-items-center">
                    <i class="fas fa-exclamation-triangle me-2"></i>
                    <h5 class="mb-0">维修监控</h5>
                </div>
                <div class="card-body">
                    {% if maintenance_warnings %}
                        <ul class="list-group list-group-flush">
                            {% for warning in maintenance_warnings %}
                                <li class="list-group-item d-flex justify-content-between align-items-center">
                                    车辆 {{ warning.bus.bus_id }} 已维修 
                                    <strong>{{ warning.days_since_start }}</strong> 天
                                    {% if warning.remaining_days == 0 %}
                                        <span class="badge bg-danger rounded-pill">已超期</span>
                                    {% else %}
                                        <span class="badge bg-warning rounded-pill">进行中</span>
                                    {% endif %}
                                </li>
                            {% endfor %}
                        </ul>
                    {% else %}
                        <p class="text-success mb-0"><i class="fas fa-check-circle me-2"></i>暂无维修任务</p>
                    {% endif %}
                </div>
            </div>
        </div>

        <!-- 当日排班表格增强 -->
        <div class="col-12 mb-4">
            <div class="card">
                <div class="card-header bg-info text-white">
                    <h5 class="mb-0"><i class="fas fa-clock me-2"></i>今日排班</h5>
                </div>
                <div class="card-body p-0">
                    {% if today_schedules %}
                        <div class="table-responsive">
                            <table class="table table-striped mb-0">
                                <thead class="table-dark">
                                    <tr>
                                        <th>发车时间</th>
                                        <th>车牌号</th>
                                        <th>司机姓名</th>
                                        <th>工号</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for schedule in today_schedules %}
                                        <tr>
                                            <td>{{ schedule.departure_time|date:"H:i" }}</td>
                                            <td>{{ schedule.bus.bus_id }}</td>
                                            <td>{{ schedule.driver.name }}</td>
                                            <td>{{ schedule.driver.driver_id }}</td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    {% else %}
                        <p class="text-center text-muted p-3 mb-0">今日无排班</p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}